<!--
 * @Description: 伪类选择器
 * @Author: rendc
 * @Date: 2022-09-20 11:12:48
 * @LastEditors: rendc
 * @LastEditTime: 2022-09-20 11:29:54
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>伪类选择器</title>
  <style>
    body {
      margin: 0;
    }

    .inner {
      border: 1px solid hotpink;
    }

    .inner>*:first-child {
      /* background-color: hotpink; */
    }

    .inner>*:last-child {
      /* background-color: yellowgreen; */
    }

    .inner>*:nth-child(3) {
      /* background-color: skyblue; */
    }

    /* 奇数 */
    .inner>*:nth-child(odd) {
      /* background-color: skyblue; */
    }

    /* 偶数 */
    .inner>*:nth-child(even) {
      /* background-color: skyblue; */
    }

    /* 倒数第2个子节点 */
    .inner>*:nth-last-child(2) {
      /* background-color: yellow; */
    }

    .inner>*:first-of-type {
      /* background-color: yellow; */
    }

    .inner>*:last-of-type {
      /* background-color: green; */
    }

    .inner>*:nth-of-type(2) {
      /* background-color: pink; */
    }

    .inner>*:only-child {
      /* background-color: pink; */
    }

    .inner>*:only-of-type {
      background-color: pink;
    }
  </style>
</head>

<body>
  <div class="outer">
    <div class="inner">
      <span>span1</span>
      <span>span2</span>
      <p>p1</p>
      <p>p2</p>
      <p>p3</p>
    </div>
    <div class="inner">
      <span>span1</span>
      <span>span2</span>
      <p>p1</p>
      <p>p2</p>
      <p>p3</p>
    </div>
    <div class="inner">
      <span>span1</span>
      <span>span2</span>
      <p>p1</p>
      <p>p2</p>
      <p>p3</p>
    </div>
    <div class="inner">
      <span>span1</span>
    </div>
    <div class="inner">
      <span>span1</span>
      <span>span2</span>
      <p>p1</p>
      <div>div1</div>
    </div>
  </div>
</body>

</html>